﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace System
{
    static class UnityHelper
    {
        public static int GetFloorValue(float value)
        {
            int ret = (int)Math.Floor(value);
            if (Math.Abs(value - 1 - ret) < 0.0001f)
                return ret + 1;
            else
                return ret;
        }

        public static Point GetPointFromVector3(Vector3 v, float size = 32.0f)
        {
            return new Point(UnityHelper.GetFloorValue(v.X/ size), UnityHelper.GetFloorValue(v.Z / size));
        }

        private static Random _Random = new Random();
        public static int Next(int max)
        {
            return _Random.Next(max);
        }

        public static float DefensePercent(int defense)
        {
            return (float)Math.Pow(0.95f, defense);
        }

        public static float GridDistance(Vector3 a, Vector3 b)
        {
            Vector3 r = a - b;
            if (Math.Abs(r.X) < Math.Abs(r.Z))
                return Math.Abs(r.X);
            else
                return Math.Abs(r.Z);
        }
    }
}
